<?php
/**
 * Created by jinqiang on 2025/5/19 17:56.
 * Copyright (c) 2025, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Soa;


use App\Http\Controllers\Controller;
use App\Http\Services\Soa\VerifyPriceService;
use Illuminate\Http\Request;

class VerifyPriceController extends Controller
{
    public function list(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $verifyPriceService->search($param);
        return result($res);
    }

    //删除
    public function del(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $verifyPriceService->del((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //锁定、解锁
    public function lock(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'id' => 'required',
            'state' => 'required|in:0,1'
        ]);
        $param = $request->all();
        $res = $verifyPriceService->lock((Int)$param['id'], (Int)$param['state']);
        return $res['code'] === 0 ? success($param['state'] == 1 ? "锁定成功" : "解锁成功") : error($res['msg'], $res);
    }

    //详情
    public function detail(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $verifyPriceService->detail((Int)$param['id']);
        return result($res);
    }

    //设计款号
    public function style(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'style_number' => 'required|string|min:4'
        ]);
        $param = $request->all();
        $res = $verifyPriceService->getStyleBom($param['style_number']);
        return result($res);
    }

    //保存
    public function save(Request $request, VerifyPriceService $verifyPriceService)
    {
        $this->validate($request, [
            'form' => 'required',
            'bom_list' => 'required',
            'item_list' => 'required',
            't59_list' => 'required',
            't76_list' => 'required',
            'printing_list' => 'required',
        ]);
        $param = $request->all();
        $res = $verifyPriceService->save($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }
}
